<template>
  <div>
    <!-- 标题 -->
    <van-cell title="搜索历史">
      <van-icon name="delete-o" v-if="!isDel" @click="isDel = true" />
      <div v-else>
        <span @click="$store.commit('SET_HISTORYS', [])">全部删除</span>
        <span @click="isDel = false">完成</span>
      </div>
    </van-cell>
    <!-- 搜索历史 -->
    <van-cell
      v-for="item in historys"
      :key="item"
      :title="item"
      @click="$emit('updata-keywords', item)"
    >
      <van-icon
        name="close"
        v-if="isDel"
        @click="
          $store.commit(
            'SET_HISTORYS',
            historys.filter((i) => i !== item)
          )
        "
      ></van-icon>
    </van-cell>
  </div>
</template>

<script>
import { mapState } from 'vuex'
export default {
  name: 'SearchHistory',
  data() {
    return {
      isDel: false
    }
  },
  computed: {
    ...mapState(['historys'])
  },
  methods: {}
}
</script>

<style scoped lang="less"></style>
